package com.mlk.engUser.api;

import com.mlk.constant.OK;
import com.mlk.core.component.page.Pager;
import com.mlk.core.util.ServerResponse;
import com.mlk.core.util.ServletUtils;
import com.mlk.engUser.po.EngUser;
import com.mlk.engUser.service.EngUserService;
import com.mysql.fabric.Server;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * 用户管理部分
 */
@RequestMapping("/api/eng/user")
@Controller
@Api(value = "用户管理")
public class EngUserAPI {

    @Resource
    private EngUserService engUserService;

    @GetMapping("getPhoneVerifyCode")
    @ResponseBody
    @ApiOperation("获取手机验证码")
    @OK
    public ServerResponse getPhoneVerifyCode(String phone){
        return this.engUserService.getPhoneVerifyCode(phone);
    }

    /**
     * 用户注册
     * @return
     */
    @ResponseBody
    @PostMapping("register")
    @ApiOperation(value = "用户注册")
    @OK
    public ServerResponse register(EngUser user){
        return this.engUserService.register(user, Integer.parseInt(ServletUtils.getRequest().getParameter("verifyCode")));
    }

    /**
     * 上传店铺照片
     * @param openId
     * @param files
     * @return
     */
    @PostMapping(value = "uploadShopPic")
    @ResponseBody
    @ApiOperation("上传店铺相关照片")
    @OK
    public ServerResponse uploadShopPic(String openId, MultipartFile[] files,int type){
        return this.engUserService.uploadShopPic(openId,files,type);
    }

    /**
     * 修改密码
     * @param openId
     * @param newPassword
     * @return
     */
    @PostMapping("modifyPassword")
    @ResponseBody
    @ApiOperation("修改密码")
    public ServerResponse modifyPassword(String openId,String newPassword){
        return this.engUserService.modifyPassword(openId,newPassword);
    }

    /**
     * 判断一个用户是否注册过.
     * @param openId
     * @return
     */
    @GetMapping("checkIsRegistered")
    @ResponseBody
    @ApiOperation("校验是否注册过")
    @OK
    public ServerResponse checkIsRegistered(String openId){
        return this.engUserService.checkIsRegistered(openId);
    }

    /**
     * 用户总收益
     */
    @GetMapping("findTotalIncome")
    @ResponseBody
    @ApiOperation("用户总收益")
    public ServerResponse findTotalIncome(String openId){
        return this.engUserService.findTotalIncome(openId);
    }

    /**
     * 用户总收益明细
     */
    @GetMapping("findTotalIncomeDetail")
    @ResponseBody
    @ApiOperation("用户总收益明细")
    public Pager findTotalIncomeDetail(String openId){
        return this.engUserService.findTotalIncomeDetail(openId);
    }

    /**
     * 查询用户的当前积分
     * @return
     */
    @GetMapping("getUserCurrentScore")
    @ResponseBody
    public ServerResponse getUserCurrentScore(String openId){
        return this.engUserService.getUserCurrentScore(openId);
    }

    /**
     * 查询用户当前余额
     * @return
     */
    @ResponseBody
    @GetMapping("getUserCurrentRemain")
    public ServerResponse getUserCurrentRemain(String openId){
        return this.engUserService.getUserCurrentRemain(openId);
    }
}
